{extend name="admin@index_layout"/}
{block name="main"}


<div class="layui-card">
    <div class="layui-card-header">商家列表</div>
    <div class="layui-card-body">
        <table class="layui-hide" id="currentTable" lay-filter="currentTable"
               data-auth-add="{:$auth->check('business.business/add')}"
               data-auth-edit="{:$auth->check('business.business/edit')}"
               data-auth-delete="{:$auth->check('business.business/del')}"
        ></table>
    </div>
</div>


<script type="text/html" id="barTool">

    <a data-open='{:url("edit")}?id={{ d.id }}'
       class="layui-btn layui-btn-xs {:$auth->check('business.business/edit')?'':'layui-hide'}"
       title="编辑" data-full="true">编辑</a>
    <a data-open='{:url("vorder")}?id={{ d.id }}'
       class="layui-btn layui-btn-xs  layui-btn-normal {:$auth->check('business.business/vorder')?'':'layui-hide'}"
       title="编辑" data-full="true">核销订单</a>


    <a href="javascript:;" onclick="wk.confirm('{{d.id}}','{:url('editStatus')}','确定切换状态吗？')"
       class="layui-btn layui-btn-danger layui-btn-xs" title="状态">切换商家状态</a>

<!--    <a data-open='{:url("change")}?id={{ d.id }}'-->
<!--       class="layui-btn layui-btn-xs layui-btn-normal {:$auth->check('business.business/change')?'':'layui-hide'}"-->
<!--       title="账号转移">账号转移</a>-->

<!--    <a data-open='{:url("look")}?id={{ d.id }}'-->
<!--       class="layui-btn layui-btn-xs layui-btn-warm {:$auth->check('business.business/look')?'':'layui-hide'}"-->
<!--       title="数据查看" data-full="true">数据查看</a>-->

<!--    <a data-open='{:url("del")}?id={{ d.id }}'-->
<!--       class="layui-btn layui-btn-xs layui-btn-danger {:$auth->check('business.business/del')?'':'layui-hide'}"-->
<!--       title="账号转移">删除商家</a>-->

</script>



<!--操作模板-->

{/block}
{block name="script"}
<script>
    var selectElement=null;
    layui.use('yznTable', function () {
        var table = layui.yznTable;
        var init = {
            table_elem: '#currentTable',
            table_render_id: 'currentTable',
            add_url: "{:url('add')}",
            edit_url: "{:url('edit')}",
            delete_url: "{:url('del')}",
        };
        var proviec = {:json_encode($proviec)};
        table.render({
            init: init,
            autoWidth: true,
            toolbar: ['refresh',],
            url: '{:url("index")}',
            cols: [
                [
                    // {type: 'checkbox', fixed: 'left'},
                    {field: 'id', width: '4%', title: 'ID'},
                    {field: 'shop_name', align: "center", width: '15%', title: '商家名称', searchOp: 'like'},
                    {field: 'nickname', align: "center", width: '15%', title: '关联会员', search: false},
                    {field: 'people', align: "center", width: '10%', title: '商家负责人', searchOp: 'like'},
                    {field: 'phone', align: "center", width: '10%', title: '电话'},
                    {
                        field: 'province',
                        align: "center",
                        width: '15%',
                        title: '省',
                        hide: true,
                        selectList: proviec
                    },
                    {field: 'city', align: "center", width: '15%', title: '市',hide: true,
                        selectList: {}},
                    {field: 'c_address', align: "center", width: '20%', title: '商家地址'},
                    // {field: 'operate_cate', align: "center", width: '15%', title: '经营品类',search: false},
                    // {field: 'operation_status', align: "center", width: '15%', title: '营业状态',templet: function (d) {
                    //         if (d.operation_status == 0) {
                    //             return '<span style="color: red">打烊</span>';
                    //         } else if (d.operation_status == 1) {
                    //             return '<span style="color: green">经营中</span>';
                    //         }
                    //     }, selectList: {1:'经营中',0: '打烊'}},
                    // {field: 'operate_type', align: "center", width: '15%', title: '经营形式',search: false},

                    {
                        field: 'status', align: "center", width: '8%', title: '商家状态', templet: function (d) {
                            if (d.status == 0) {
                                return '<span style="color: red">待审核</span>';
                            } else if (d.status == 1) {
                                return '<span style="color: green">正常</span>';
                            } else if (d.status == 2) {
                                return '<span style="color:  #00B7EE ">冻结</span>';
                            } else if (d.status == 3) {
                                return '<span style="color: orangered">审核失败</span>';
                            } else {
                                return '<span>未知</span>';
                            }
                        }, search: false
                    },
                     {field: 'order_num', align: "center", width: '8%', title: '核销数量',search: false},
                    {field: 'create_time', align: "center", width: '15%', title: '入驻时间', search: 'range'},

                    {fixed: 'right', align: "center", width: '20%', title: '操作', toolbar: '#barTool'}//delete'
                ]
            ],
            page: {}
        });
        yznTable.bindevent();
        selectElement = document.getElementById('c-province');
        selectElement.setAttribute("lay-filter", "c-province");
        form1();
        selectElement2 = document.getElementById('searchFieldset_currentTable');
        selectElement2.classList.remove("layui-hide");
        var element = document.getElementById('layui-input-search');
        element.parentNode.removeChild(element);
        console.log(selectElement2);

    });
    function form1(){
        layui.use('form', function () {
            var form = layui.form;
            form.on('select(c-province)', function (data) {
                console.log(data.value);
                $.ajax({
                    type: "POST",//规定传输方式
                    url: "{:url('getc_cate2')}",//提交URL
                    data: {'id':data.value},//提交的数据
                    success: function(result){
                        if(result.code == 200){
                            $("#c-city").empty();
                            var str = "<option value>- 全部 -</option>";
                            $.each(result.data, function(i, val){
                                str += '<option value='+val.id+'>'+val.name+'</option>'
                            });
                            $("#c-city").append(str);
                            layui.form.render('select');
                        }
                    },
                    error: function() {
                        alert("获取信息失败")
                    }
                });
            })
        });
    }




</script>
{/block}